//
//  XXWebViewController.m
//  Stream
//
//  Created by shaw on 16/8/6.
//  Copyright © 2016年 showshaw. All rights reserved.
//

#import "XXWebViewController.h"

@interface XXWebViewController () <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UIButton *forwardButton;
@property (weak, nonatomic) IBOutlet UIButton *refreshButton;

@end

@implementation XXWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView.delegate = self;
    

    
    NSURL * url = [NSURL URLWithString:_URL];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}

- (IBAction)clickBackButton:(UIButton *)sender {
    if (self.webView.canGoBack)
    {
        [self.webView goBack];
    }
}
- (IBAction)clickForwardButton:(UIButton *)sender {
    if (self.webView.canGoForward)
    {
        [self.webView goForward];
    }
}
- (IBAction)clickRefreshButton:(UIButton *)sender {

    [self.webView reload];
}

#pragma mark - UIWebViewDelegate
//begin load
-(void)webViewDidStartLoad:(UIWebView *)webView
{
    self.title = @"加载中...";
    self.backButton.enabled = self.webView.canGoBack;
    self.forwardButton.enabled = self.webView.canGoForward;

}
//finish load
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}


-(void)dealloc
{
    self.webView = nil;
}


@end
